//1052.爱生气的书店老板
//https://leetcode.cn/problems/grumpy-bookstore-owner/?envType=daily-question&envId=2024-04-23
class Solution {
public:
    int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int minutes) {
        int n = customers.size();
        int l = 0, r = 0;
        //计算minutes分钟可以最大让顾客满意的程度
        int num = 0;
        int maxn = 0; //
        while (r < n)
        {
            num += customers[r] * grumpy[r];
            while ((r - l) == minutes)
            {
                num -= customers[l] * grumpy[l];
                ++l;
            }
            ++r;
            maxn = max(maxn, num);
        }
        int sum = 0;
        //原本有效的时间
        for (int i = 0; i < n; ++i) sum += customers[i] * (!grumpy[i]);
        return sum + maxn;
    }
};